﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO;
using System.IO.IsolatedStorage;
using Zeus.UserControls;

namespace Zeus.Classes
{
    public class ControlsProperties
    {
        public string Data { get; set; }

      
        public void GenerateCode(string Text , FrameworkElement Name)
        {
            StreamWriter writer = null;
            IsolatedStorageFile isolated = IsolatedStorageFile.GetUserStoreForApplication();
            IsolatedStorageFileStream strm = new IsolatedStorageFileStream("./" + Project.ProjectName + "/App_Code/" +  Name +".cs",FileMode.OpenOrCreate ,FileAccess.ReadWrite, isolated);
            writer = new StreamWriter(strm);
            writer.WriteLine(Text);
            writer.Close();
            strm.Close();
        }

        public void Content(TextBlock B, TextBox TB)
        {
            
            if (TB.Text != "")
            {
                B.Text = TB.Text;
                string text = B.Name + ".Content = " + TB.Text;
                Data += text + Environment.NewLine;  
                
            }
            
        }
        //public void BGC(FrameworkElement C, ColorPicker CP)
        //{
        //    C.size
        //    C.Background = CP.SelectedColor;
        //}


        //public void BackGroundColor(FrameworkElement B, ColorPicker CP)
        //{
        //    B.Background = CP.SelectedColor;
        //}

        //public void ForeColor(FrameworkElement B, ColorPicker CP)
        //{
        //    B.Foreground = CP.SelectedColor;
        //}

        //public void Enabled(FrameworkElement B, CheckBox CB)
        //{
        //    if (CB.IsChecked == false)
        //        B.IsEnabled = false;
        //    else
        //        B.IsEnabled = true;
        //}

        public void Size(FrameworkElement B, TextBox TB1, TextBox TB2)
        {

            if (TB1.Text != "")
            {
                double x = double.Parse(TB1.Text);
                B.Width = x;
                string text = B.Name + ".Width = " + TB1.Text;
                Data += text + Environment.NewLine; 
            }
            else
                B.Width = B.Width;
            if (TB2.Text != "")
            {
                double y = double.Parse(TB2.Text);
                B.Height = y;
                string text2 = B.Name + ".Height = " + TB1.Text;
                Data += text2 + Environment.NewLine;
            }
            else
                B.Height = B.Height;
            
             
        }

        //public void Visible(FrameworkElement B, ComboBox CB)
        //{
        //    if (CB.SelectedItem.ToString() == "Visible" || CB.SelectedItem.ToString() == null)
        //        B.Visibility = Visibility.Visible;
        //    else
        //        B.Visibility = Visibility.Collapsed;

        //}

        //public void BorderThickness(FrameworkElement B, TextBox TB1, TextBox TB2, TextBox TB3, TextBox TB4)
        //{

        //    if (TB1.Text != "")
        //    {
        //        double w = double.Parse(TB1.Text);
        //        if (TB2.Text != "")
        //        {
        //            double x = double.Parse(TB2.Text);
        //            if (TB3.Text != "")
        //            {
        //                double y = double.Parse(TB3.Text);
        //                if (TB4.Text != "")
        //                {
        //                    double z = double.Parse(TB4.Text);
        //                    B.BorderThickness = new Thickness(w, x, y, z);
        //                }
        //            }
        //        }
        //    }
        //}

        public void Opacity(FrameworkElement B, TextBox TB)
        {
            if (TB.Text != "")
            {
                double x = double.Parse(TB.Text);
                if ((x >= 0) && (x <= 1))
                    B.Opacity = x;
                string text = B.Name + ".Opacity = " + TB.Text;
                Data += text + Environment.NewLine;  ; 
            }
            
        }

        public void Margin(FrameworkElement B, TextBox TB1, TextBox TB2, TextBox TB3, TextBox TB4)
        {


            if (TB1.Text != "")
            {
                double w = double.Parse(TB1.Text);
                if (TB2.Text != "")
                {
                    double x = double.Parse(TB2.Text);
                    if (TB3.Text != "")
                    {
                        double y = double.Parse(TB3.Text);
                        if (TB4.Text != "")
                        {
                            double z = double.Parse(TB4.Text);
                            B.Margin = new Thickness(w, x, y, z);
                        }
                    }
                }
            }
        }

        public void Name(FrameworkElement B, TextBox TB)
        {
            if (TB.Text != "")
            {
                B.Name = TB.Text;
                string text = B.Name + ".Name = " + TB.Text;
                Data += text + Environment.NewLine; 
            } 
        }

        

    }
}
